/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package brisollogic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Alex
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Logic logic = new Logic();
        Credentials cred = UserCredentials.getInstance("testadmin@test.com", "Pa$$w0rd");
        User user = null;
        try {
            logic.insertUserIntoDb(user);
        } catch(SQLException | ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
        
    }

    public static void testInsUser() throws IOException, SQLException, ClassNotFoundException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Logic l = new Logic();

        System.out.println("Username?");
        String usern = reader.readLine();

        System.out.println("email?");
        String email = reader.readLine();

        System.out.println("Status?");
        User.Status status = User.Status.valueOf(reader.readLine());

        System.out.println("Password?");
        String passwd = reader.readLine();


        User user = new User.UserBuilder(UserCredentials.getInstanceHashPassword(email, passwd)).name(usern).status(status).build();
        l.insertUserIntoDb(user);
    }

    private static void testShowAllUsers(Logic logic) {
        List<User> users = null;
        try {
            users = logic.showAllUsers();
        } catch (SQLException | ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
        for (User user : users) {
            System.out.println("Username " + user.getName());
        }
    }

    private static void testInsProduct() throws IOException, SQLException, ClassNotFoundException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Logic l = new Logic();
        System.out.println("Model navn?");
        String modeln = reader.readLine();

        System.out.println("Specs?");
        String specs = reader.readLine();

        System.out.println("Cat?");
        String cat = reader.readLine();

        System.out.println("Picture name?");
        String pic = reader.readLine();

        Product prod = new Product(modeln, specs, Product.Category.valueOf(cat), pic);
        l.insertProductIntoDb(prod);
    }
    
    private static void testGetUserByCredential(Logic logic, Credentials cred) {
        User user = null;
        try {
            user = logic.getUserByCredential(cred);
        } catch (SQLException | ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
        if (user != null) {
            System.out.printf("User details\nName: %s\nEmail: %s\nPassword: %s\n", user.getName(), user.getEmail(), user.getPassword());
        } else {
            System.out.println("Couldn't find a user with macthing Credentials");
        }        
    }
}
